<template>
  <div class="saveUpdate">
    <el-dialog :close-on-click-modal="false" title="添加黑名单用户" :visible.sync="showDialog" @close="$emit('update:showUpdate', false)"
               :showUpdate="showUpdate" width="500px">
      <el-form :model="DetailInfo" ref="saveChn" label-width="120px" size="mini">
        <dialog-wrapper :MaxWidth="400">

          <el-form-item label="游戏平台："  prop="mch_id" :rules="[{ required: true, message: '游戏平台不能为空'}]">
            <el-select v-model="DetailInfo.mch_id" clearable  placeholder="请选择">
              <el-option v-for="item in MerchantsList" :key="item.id" :label="item.name" :value="item.id" ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="用户ID："  prop="user_id" :rules="[{ required: true, message: '用户ID不能为空'}]">
            <el-input v-model="DetailInfo.user_id" placeholder="用户ID"></el-input>
          </el-form-item>

          <el-form-item label="备注：">
            <el-input v-model="DetailInfo.remark" type="textarea" placeholder="请输入备注"></el-input>
          </el-form-item>
        </dialog-wrapper>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:showUpdate', false)" size="small">取 消</el-button>
        <el-button v-if="id" type="primary" :loading="loading" @click="updateDetail" size="small">确 定</el-button>
        <el-button v-else type="primary" :loading="loading" @click="saveDetail" size="small">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import DialogWrapper from '@/components/DialogWrapper'
  import { saveBlackList } from '@/api'
  export default {
    components: { DialogWrapper },
    data() {
      return {
        showDialog: this.showUpdate,
        loading: false,
        DetailInfo: {},
        MchList:[],
      }
    },
    props: {
      MerchantsList: {
        type: Array
      },
      showUpdate: {
        type: Boolean,
        default: false
      },
      id: {
        type: Number
      },
      AgencyType: {
        type: Object
      },
      settleCycle: {
        type: Object
      },
    },
    methods: {
      saveDetail(){
        this.$refs.saveChn.validate(valid => {
          if (valid) {
            saveBlackList(this.DetailInfo).then(res => {
              if(res.status === 0){
                this.$message({ message: '新增成功。',type: 'success' })
                this.$emit('update:showUpdate', false)
              }
            })
          }
        })
      }
    },
    watch: {
      showUpdate() {
        this.showDialog = this.showUpdate
      }
    }
  }
</script>
